import { Component } from '@angular/core';
import { NavController,NavParams,AlertController } from 'ionic-angular';
import { HTTP } from '@ionic-native/http';

import { IndexPage } from '../index/index';


@Component({
  selector: 'page-fortpas2',
  templateUrl: 'fortpas2.html'
})
export class Fort2Page {
  
  userPass:string;
  userPassword:string;
  id:number;
  public url:string ="http://118.31.79.20:8080/";//接口地址
  public loginurl:string = this.url + "Stock/login/updatePwdByMobile.do";//忘记密码接口
  
  constructor(public navCtrl: NavController,public http:HTTP, navParams: NavParams,private malert:AlertController) {
      this.id = navParams.get('items');
    //   alert("接受参数" + navParams.get('items'));
    //   alert(" 接受的参数"+this.id);
  }

  login(){
    // 正则判断
    let iph = /^(?!(?:\d*$))[A-Za-z0-9]{6,20}$/;
   
    if(this.userPass =="" || this.userPass == null ||this.userPassword =="" || this.userPassword == null ){
       
        this.mWinds("您好，密码不能为空");
        return false;
    }else if(this.userPass != this.userPassword){
         
          this.mWinds("您好，两次密码不一致!!");
          return false;
    }else if(!iph.test(this.userPass) || !iph.test(this.userPassword)){
       
      this.mWinds("您好，密码格式不正确!!");
        return false;
    }else{
      // 返回数据
     
       this.http.post(this.loginurl,{"mobile":this.id,"password":this.userPassword},{})   //接口。发送的数据
              .then(data => {
                  // console.log("请求成功");
                 let data_d=JSON.parse(data.data); 
                if(data_d.flag == true){    //成功跳转等页面
                    
                      this.navCtrl.push(IndexPage);
                      
                }else{
                  this.mWinds("您好，用户名不存在!!");
                    return false;
                }
                
              }).catch(error => {
                 this.mWinds("请求失败");
                  console.log(error);
              
              });
       
    }

  }
    /**
    * 自定义弹框
    */
    mWind(msg){
        let alert= this.malert.create({
      title :"提示",
      message:msg,
      buttons:[{
        text:'取消',
        handler:()=>{         
        }
      },{
        text:'确定',
        handler:()=>{       
        }
      }],
      
    });
  alert.present();

    }
    /**
     * 无按钮
     * @param msg 
     */
    mWinds(msg){
        let alert= this.malert.create({
      title :"提示",
      message:msg,     
    });
  alert.present();

    }

}
